<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>success.jsp</title>

</head>
<body>
<h1>
    用户信息
</h1>
<h2>
    ${teacher}
</h2>


<c:choose>
    <c:when test="${empty teacher}">
        <%--  为空，说明没有登陆，返回 登陆界面      --%>
        <jsp:forward page="/index.jsp"/>
    </c:when>
    <c:otherwise>
        <%-- 登陆了，显示 增、删、该、查       --%>


        <h1>所有的学生</h1>
        <c:choose>
            <c:when test="${empty studentList}">
                <jsp:forward page="/student/getAll.action"/>
            </c:when>
            <c:otherwise>

                <table>
                    <tr>
                        <th>sid</th>
                        <th>sname</th>
                        <th>spwd</th>
                        <th>spthot</th>
                        <th>sbirthday</th>
                    </tr>
                    <c:forEach items="${studentList}" var="stu">
                        <tr>
                            <td>${stu.sid}</td>
                            <td>${stu.sname}</td>
                            <td>${stu.spwd}</td>
                            <td>
                                <a href="${pageContext.request.contextPath}/student/download.action?fileName=${stu.sphoto}">
                                        <%--                                    --%>
                                    <img src="${pageContext.request.contextPath}/files/${stu.sphoto}" alt="头像"
                                         height="20px"
                                         width="20px">
                                </a>
                            </td>
                            <td>${stu.sbirthdayStr}</td>
                        </tr>
                    </c:forEach>


                </table>
            </c:otherwise>
        </c:choose>

        <hr>
        <hr>

        <h1>添加一个学生</h1>
        <h2>${message}</h2>
        <form action="${pageContext.request.contextPath}/student/upload.action"
              method="post" enctype="multipart/form-data"
        >
            姓名 ：<input type="text" name="sname"> <br>
            密码 ：<input type="text" name="spwd"> <br>
            头像 ：<input type="file" name="sphoto"> <br>
            生日 <input type="date" name="sbirthday"> <br>
            <input type="reset" value="重填"> &nbsp; <input type="submit" value="提交">
        </form>


        <hr>
        <hr>


        <h1>根据 tid 删除一个学生</h1>
        <h2>${message}</h2>

        <form action="${pageContext.request.contextPath}/student/deloneByTid.action" method="post">
            tid <input type="number" name="tid">
            <input type="reset" value="重填"> &nbsp; <input type="submit" value="提交">
        </form>

        <hr>
        <hr>

        <h1>更新一个学生</h1>
        <h2>${message}</h2>
        <form action="${pageContext.request.contextPath}/student/updateOne.action"
              method="post" enctype="multipart/form-data"
        >
            sid : <input type="number" name="sid"> <br>
            姓名 ：<input type="text" name="sname"> <br>
            密码 ：<input type="text" name="spwd"> <br>
            头像 ：<input type="file" name="sphoto"> <br>
            生日 <input type="date" name="sbirthday"> <br>
            <input type="reset" value="重填"> &nbsp; <input type="submit" value="提交">
        </form>


        <hr>
        <hr>
        <h1>获取一个学生</h1>

        <form action="${pageContext.request.contextPath}/student/getOneByTid.action" method="post">
            tid <input type="text" name="tid">
            <input type="reset" value="重填"> &nbsp; <input type="submit" value="提交">
        </form>
        <table>
            <tr>
                <th>sid</th>
                <th>sname</th>
                <th>spwd</th>
                <th>spthot</th>
                <th>sbirthday</th>
            </tr>
            <tr>
                <td>${student.sid}</td>
                <td>${student.sname}</td>
                <td>${student.spwd}</td>
                <td>
                    <a href="${pageContext.request.contextPath}/student/download.action?fileName=${student.sphoto}">
                            <%--                                    --%>
                        <img src="${pageContext.request.contextPath}/files/${student.sphoto}" alt="头像"
                             height="20px"
                             width="20px">
                    </a>
                </td>
                <td>${student.sbirthdayStr}</td>
            </tr>


        </table>

    </c:otherwise>
</c:choose>

</body>
</html>